<template>
  <div class="flex-column-center" style="margin-top: 200px;">
    <p>最终得分</p>
    <p style="font-size: 30px; font-weight: bold;margin: 0 0 50px 0;">{{result.result.sumnum}}分</p>
    <!-- <Button type="primary" @click="goPaper">查看试卷</Button> -->
    <Button type="primary" size="large" @click="checkPaper" style="font-size: 18px font-weight: bold;margin-bottom: 20px;" >
      查看试卷
    </Button>
    <Button type="primary" size="large" @click="goLogin" style="font-size: 18px font-weight: bold;">
      <span v-if="time === 0">返回首页</span>
      <span v-else>{{time}}秒后自动返回首页</span>
    </Button>

    <Modal :width="1366" v-model="show" title="试卷详情" id="exam-person">
      <paper-preview :data="paperData"></paper-preview>
      <div slot="footer">
      </div>
    </Modal>
  </div>

</template>

<script>
import Cookies from 'js-cookie';
import axios from 'axios'
import inforCard from '../home/components/inforCard.vue';
import paperPreview from '../preview/paper-preview.vue'

export default {
    name: 'exam-score',
    components: {
        inforCard,
        paperPreview
    },
    data () {
      return {
        show: false,
        paperData: {},
        time: 60,
        result: {}
      }
    },
    mounted () {
      this.CountDown(this.time)
    },
    methods: {
      goPaper () {
        this.$router.replace({
            name: 'priview'
        });
      },
      goLogin () {
        // Cookies.remove('examinee');
        // Cookies.remove('canNumber');
        this.$router.replace({
            name: 'examperson',
        });
        // this.$router.replace({
        //     name: 'login'
        // });
      },
      CountDown (maxtime) {
          let time = maxtime;
          this.timer = setInterval(() => {
              if (time > 0) {
                  let minutes = Math.floor(time / 60);
                  let seconds = Math.floor(time % 60);
                  this.time = seconds;
                  --time;
              } else {
                  clearInterval(this.timer)
                  this.goLogin()
              }
          }, 1000);
      },
      checkPaper (row) {
        clearInterval(this.timer)
        this.time = 0
        this.show = true
        // 获取试卷
        let data = {}
        if (this.result.modeltestid) {
          data = {testid: this.result.modeltestid, userid: this.result.result.userid}
        } else {
          data = {testid: this.result.result.testid, userid: this.result.result.userid}
        }
        axios.post('rs/logic/getusertestquinfo', {data: data}).then(res => {
          this.paperData = {
            modeltestflag : "false",
            testinfo: res.data.testinfo,
            tests: [res.data.oneques, res.data.douques, res.data.judques],
            userinfo: row
          }
          // this.show = false
        }).catch(error => {
          this.$Message.warning({
            content: '获取试卷失败'
          })
        }).finally(() => {

        })
      },
    },
    beforeRouteEnter (to, from, next) {
      next(vm => {
        vm.result = Object.assign({}, to.params)
      })
    },
    beforeDestroy () {
      clearInterval(this.timer)
    }
};
</script>
